using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

namespace com.yoozoo.gta.Gameplay.PVE.Editor
{
    public class PveAnimatorTemplate
    {
        private static AnimatorController templateController;
        private static Animator templateAnimator;
        private static string templatePath = "Assets/Arts/Character/Role/soldier/Animator/RPG/Soldier.controller";

        private static void LoadTemplate()
        {
            templateAnimator = AssetDatabase.LoadAssetAtPath<Animator>(templatePath);
            templateController = templateAnimator.runtimeAnimatorController as AnimatorController;
        }
        
        [MenuItem("GTATools/GamePlay/PVE/AnimatorTemplate/HitLayer", false, 66778899)]
        public static void HitLayer()
        {
            /*LoadTemplate();
            var templateLayerIndex = templateAnimator.GetLayerIndex("HitLayer");
            var templateStateMachine = templateController.layers[templateLayerIndex].stateMachine;
            //var templateTransitions = templateStateMachine.GetStateMachineTransitions(templateStateMachine);
            
            var layerIndex = templateAnimator.GetLayerIndex("HitLayer");
            var stateMachine = templateController.layers[layerIndex].stateMachine;
            //var transitions = stateMachine.GetStateMachineTransitions(stateMachine);

            Dictionary<string, AnimatorState> templateStates = new Dictionary<string, AnimatorState>();
            Dictionary<string, AnimatorState> states = new Dictionary<string, AnimatorState>();
            
            for (int i = 0; i < templateStateMachine.states.Length; i++)
            {
                templateStates.Add(templateStateMachine.states[i].state.name,templateStateMachine.states[i].state);
                bool needAdd = true;
                for (int j = 0; j < stateMachine.states.Length; j++)
                {
                    if (stateMachine.states[j].state.name == templateStateMachine.states[i].state.name)
                    {
                        states.Add(stateMachine.states[j].state.name,stateMachine.states[j].state);
                        needAdd = false;
                        break;
                    }
                }

                if (needAdd)
                {
                    stateMachine.AddState(templateStateMachine.states[i].state,
                        templateStateMachine.states[i].position);
                    states.Add(stateMachine.states[stateMachine.states.Length-1].state.name,stateMachine.states[stateMachine.states.Length-1].state);
                    Debug.LogError("添加了状态"+templateStateMachine.states[i].state.name);
                }
            }

            for (int i = 0; i < templateStateMachine.states.Length; i++)
            {
                var templateTransitions = templateStateMachine.states[i].state.transitions;
                var state = states[templateStateMachine.states[i].state.name];
                var transitions = state.transitions;
                for (int j = 0; j < transitions.Length; j++)
                {
                    state.RemoveTransition(transitions[j]);
                }

                for (int j = 0; j < templateTransitions.Length; j++)
                {
                    state.AddTransition(templateTransitions[j]);
                }
                state.RemoveTransition();
                for (int j = 0; j < templateTransitions.Length; j++)
                {
                    
                }
            }
            
            for (int i = 0; i < templateStateMachine.states.Length; i++)
            {
                bool needAdd = true;
                for (int j = 0; j < stateMachine.states.Length; j++)
                {
                    if (stateMachine.states[j].state.name == templateStateMachine.states[i].state.name)
                    {
                        needAdd = false;
                        break;
                    }
                }

                if (needAdd)
                {
                    stateMachine.AddState(templateStateMachine.states[i].state,
                        templateStateMachine.states[i].position);
                    Debug.LogError("添加了状态"+templateStateMachine.states[i].state.name);
                }
            }

            for (int i = 0; i < templateTransitions.Length; i++)
            {
                bool needAdd = true;
                for (int j = 0; j < transitions.Length; j++)
                {
                    if (transitions[j].)
                }
            }*/
        }
        
    }
}